package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.LogBean;
import com.project.mapper.ILogMapper;
import com.project.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class LogServiceImp implements ILogService {
    @Autowired
    private ILogMapper logMapper;

    @Override
    public IPage<LogBean> findByItem(Integer pageNO, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<LogBean> query = new QueryWrapper<>();
        IPage<LogBean> page = new Page<>(pageNO, 3);
        if (startDate!= null) {
            query.ge("l_date", startDate);
        }
        if (endDate!= null) {
            query.le("l_date", endDate);
        }
        return logMapper.selectPage(page, query);
    }

    @Override
    public void addLog(LogBean logBean) {
        logMapper.insert(logBean);
    }

    @Override
    public List<LogBean> showAllLog() {
        return logMapper.selectList(null);
    }
}
